/*
 * sysCalls.c
 *
 * Created: 5/21/2011 8:36:58 PM
 *  Author: X-Ravin
 */ 
#include "kernel.h"

//System call handler, user code calls to this INT vector.
//Code theoretically returns with SREG, Regs, PC and Stack intact.
ISR(PCINT3_vect) 
{
	//R2 - sys call number
	//R3 - parameter (lo)
	//R4 - parameter (hi)
	
	char sysCallNumber;
	char lo, hi;

	//This assembly copies the params into C variables
	//so it's easier to work with.
	asm("mov %0, r2\n\t"
		"mov %1, r3\n\t"
		"mov %2, r4\n\t"
		:"=r" (sysCallNumber), "=r" (lo), "=r" (hi)
		:);

	switch(sysCallNumber)
	{
		case 0: //Block process
			process[current_proc].state = BLOCKED;
			//Actually going to next proc handled in syscall client library.
			break;
		case 1: //Request ownership of resource
			if(isr[lo] == 0)
				isr[lo] = current_proc;
			break;
			
	}
}
